import 'package:flutter/material.dart' show Color;

typedef ColorGetter = Color Function(bool isUp);

class ChartColors {
  const ChartColors({
    this.bgColor,
    this.kLineColor,
    this.gridColor,
    this.kLineShadowColor,
    this.ma5Color,
    this.ma9Color,
    this.ma20Color,
    this.upColor,
    this.dnColor,
    this.volColor,
    this.macdColor,
    this.difColor,
    this.deaColor,
    this.kColor,
    this.dColor,
    this.jColor,
    this.rsiColor,
    this.yAxisTextColor,
    this.xAxisTextColor,
    this.maxMinTextColor,
    this.depthBuyColor,
    this.depthSellColor,
    this.markerBorderColor,
    this.markerBgColor,
    this.markerInfoNameColor,
    this.markerInfoColor,
    this.rightRealTimeBgColorFn,
    this.rightRealTimeTextColorFn,
    this.realTimeBgColorFn,
    this.realTimeTextBorderColorFn,
    this.realTimeTextColorFn,
    this.realTimeLineColorFn,
    this.realTimeLongLineColorFn,
    this.simpleLineUpColor,
    this.simpleLineDnColor,
    this.vCrossColor,
    this.hCrossColor,
    this.selectXAxisTextBgColor,
    this.selectYAxisTextBgColor,
    this.selectXAxisTextColor,
    this.selectYAxisTextColor,
  });

  //背景颜色
  final Color? bgColor;
  final Color? kLineColor;
  final Color? gridColor;
  final List<Color>? kLineShadowColor;

  final Color? ma5Color;

  final Color? ma9Color;
  final Color? ma20Color;

  ///up color
  final Color? upColor;

  ///down color
  final Color? dnColor;

  final Color? volColor;

  final Color? macdColor;

  final Color? difColor;

  final Color? deaColor;

  final Color? kColor;

  final Color? dColor;

  final Color? jColor;

  final Color? rsiColor;

  final Color? yAxisTextColor; //右边y轴刻度
  final Color? xAxisTextColor; //下方时间刻度

  final Color? maxMinTextColor; //最大最小值的颜色

  //深度颜色
  final Color? depthBuyColor;

  final Color? depthSellColor;

  //选中后显示值边框颜色
  final Color? markerBorderColor;

  //选中后显示值背景的填充颜色
  final Color? markerBgColor;

  final Color? markerInfoNameColor;

  //选中后显示值字体颜色,如果为null，默认字体颜色
  final Color? markerInfoColor;
  final ColorGetter? rightRealTimeBgColorFn;
  final ColorGetter? rightRealTimeTextColorFn;

  final ColorGetter? realTimeTextBorderColorFn;
  final ColorGetter? realTimeBgColorFn;

  //实时线. 如果为null,默认使用涨跌颜色
  final ColorGetter? realTimeTextColorFn;

  final ColorGetter? realTimeLineColorFn;

  final ColorGetter? realTimeLongLineColorFn;

  final Color? simpleLineUpColor;

  final Color? simpleLineDnColor;

  ///垂直交叉线颜色
  final Color? vCrossColor;

  ///水平交叉线颜色
  final Color? hCrossColor;

  final Color? selectXAxisTextColor;
  final Color? selectYAxisTextColor;

  final Color? selectXAxisTextBgColor;
  final Color? selectYAxisTextBgColor;

  ChartColors copyWith({
    Color? bgColor,
    Color? kLineColor,
    Color? gridColor,
    List<Color>? kLineShadowColor,
    Color? ma5Color,
    Color? ma10Color,
    Color? ma30Color,
    Color? upColor,
    Color? dnColor,
    Color? volColor,
    Color? macdColor,
    Color? difColor,
    Color? deaColor,
    Color? kColor,
    Color? dColor,
    Color? jColor,
    Color? rsiColor,
    Color? yAxisTextColor,
    Color? xAxisTextColor,
    Color? maxMinTextColor,
    Color? depthBuyColor,
    Color? depthSellColor,
    Color? markerBorderColor,
    Color? markerBgColor,
    Color? markerInfoNameColor,
    Color? markerInfoColor,
    ColorGetter? realTimeBgColor,
    ColorGetter? rightRealTimeBgColor,
    ColorGetter? rightRealTimeTextColor,
    ColorGetter? realTimeTextBorderColor,
    ColorGetter? realTimeTextColor,
    ColorGetter? realTimeLineColor,
    ColorGetter? realTimeLongLineColor,
    Color? simpleLineUpColor,
    Color? simpleLineDnColor,
    Color? vCrossColor,
    Color? hCrossColor,
    Color? selectXAxisTextColor,
    Color? selectYAxisTextColor,
    Color? selectXAxisTextBgColor,
    Color? selectYAxisTextBgColor,
  }) {
    return ChartColors(
      bgColor: bgColor ?? this.bgColor,
      kLineColor: kLineColor ?? this.kLineColor,
      gridColor: gridColor ?? this.gridColor,
      kLineShadowColor: kLineShadowColor ?? this.kLineShadowColor,
      ma5Color: ma5Color ?? this.ma5Color,
      ma9Color: ma10Color ?? this.ma9Color,
      ma20Color: ma30Color ?? this.ma20Color,
      upColor: upColor ?? this.upColor,
      dnColor: dnColor ?? this.dnColor,
      volColor: volColor ?? this.volColor,
      macdColor: macdColor ?? this.macdColor,
      difColor: difColor ?? this.difColor,
      deaColor: deaColor ?? this.deaColor,
      kColor: kColor ?? this.kColor,
      dColor: dColor ?? this.dColor,
      jColor: jColor ?? this.jColor,
      rsiColor: rsiColor ?? this.rsiColor,
      yAxisTextColor: yAxisTextColor ?? this.yAxisTextColor,
      xAxisTextColor: xAxisTextColor ?? this.xAxisTextColor,
      maxMinTextColor: maxMinTextColor ?? this.maxMinTextColor,
      depthBuyColor: depthBuyColor ?? this.depthBuyColor,
      depthSellColor: depthSellColor ?? this.depthSellColor,
      markerBorderColor: markerBorderColor ?? this.markerBorderColor,
      markerBgColor: markerBgColor ?? this.markerBgColor,
      markerInfoNameColor: markerInfoNameColor ?? this.markerInfoNameColor,
      markerInfoColor: markerInfoColor ?? this.markerInfoColor,
      realTimeBgColorFn: realTimeBgColor ?? this.realTimeBgColorFn,
      rightRealTimeBgColorFn:
          rightRealTimeBgColor ?? this.rightRealTimeBgColorFn,
      rightRealTimeTextColorFn:
          rightRealTimeTextColor ?? this.rightRealTimeTextColorFn,
      realTimeTextBorderColorFn:
          realTimeTextBorderColor ?? this.realTimeTextBorderColorFn,
      realTimeTextColorFn: realTimeTextColor ?? this.realTimeTextColorFn,
      realTimeLineColorFn: realTimeLineColor ?? this.realTimeLineColorFn,
      realTimeLongLineColorFn:
          realTimeLongLineColor ?? this.realTimeLongLineColorFn,
      simpleLineUpColor: simpleLineUpColor ?? this.simpleLineUpColor,
      simpleLineDnColor: simpleLineDnColor ?? this.simpleLineDnColor,
      vCrossColor: vCrossColor ?? this.vCrossColor,
      hCrossColor: hCrossColor ?? this.hCrossColor,
      selectXAxisTextBgColor:
          selectXAxisTextBgColor ?? this.selectXAxisTextBgColor,
      selectYAxisTextBgColor:
          selectYAxisTextBgColor ?? this.selectYAxisTextBgColor,
      selectXAxisTextColor: selectXAxisTextColor ?? this.selectXAxisTextColor,
      selectYAxisTextColor: selectYAxisTextColor ?? this.selectYAxisTextColor,
    );
  }

  factory ChartColors.light() => ChartColors.dark().copyWith(
        selectXAxisTextBgColor: const Color(0xFFF4F5F6),
        selectYAxisTextBgColor: const Color(0xFFF4F5F6),
        selectXAxisTextColor: const Color(0xFF000000),
        selectYAxisTextColor: const Color(0xFF000000),
        markerBgColor: const Color(0xFFFFFFFF),
        gridColor: const Color(0xFFF4F5F6),
        realTimeBgColor: (_) => const Color(0xFFFFFFFF),
        rightRealTimeBgColor: (_) => const Color(0xFFFFFFFF),
        hCrossColor: const Color(0xFF5C5F66),
        vCrossColor: const Color(0xFF5C5F66),
      );

  factory ChartColors.dark() => ChartColors._raw().copyWith(
        realTimeBgColor: (_) => const Color(0xff0D1722),
        rightRealTimeBgColor: (_) => const Color(0xff0D1722),
      );

  factory ChartColors._raw() => ChartColors(
        bgColor: const Color(00000000),
        kLineColor: const Color(0xff4C86CD),
        gridColor: const Color(0xff1F2533),
        kLineShadowColor: const [Color(0x554C86CD), Color(0x00000000)],
        ma5Color: const Color(0xffC9B885),
        ma9Color: const Color(0xff6CB0A6),
        ma20Color: const Color(0xff9979C6),
        upColor: const Color(0xFF1CB89E),
        dnColor: const Color(0xFFD64B54),
        volColor: const Color(0xff4729AE),
        macdColor: const Color(0xff4729AE),
        difColor: const Color(0xffC9B885),
        deaColor: const Color(0xff6CB0A6),
        kColor: const Color(0xffC9B885),
        dColor: const Color(0xff6CB0A6),
        jColor: const Color(0xff9979C6),
        rsiColor: const Color(0xffC9B885),
        yAxisTextColor: const Color(0xff60738E),
        xAxisTextColor: const Color(0xff60738E),
        maxMinTextColor: const Color(0xff8D96A6),
        depthBuyColor: const Color(0xFF1CB89E),
        depthSellColor: const Color(0xFFD64B54),
        markerBorderColor: const Color.fromRGBO(31, 37, 51, 0.96),
        markerBgColor: const Color.fromRGBO(31, 37, 51, 0.96),
        markerInfoNameColor: const Color(0xFF464C58),
        markerInfoColor: null,
        realTimeBgColorFn: (_) => const Color(0xff0D1722),
        rightRealTimeBgColorFn: (_) => const Color(0xff0D1722),
        rightRealTimeTextColorFn: (_) => const Color(0xff4C86CD),
        realTimeTextBorderColorFn: (_) => const Color(0xFFffffff),
        realTimeTextColorFn: null,
        realTimeLineColorFn: null,
        realTimeLongLineColorFn: (_) => const Color(0xff4C86CD),
        simpleLineUpColor: const Color(0xFF1CB89E),
        simpleLineDnColor: const Color(0xFFD64B54),
        vCrossColor: const Color(0xFFCFD6E5),
        hCrossColor: const Color(0xFF8D96A6),
        selectXAxisTextBgColor: const Color.fromRGBO(31, 37, 51, 0.96),
        selectYAxisTextBgColor: const Color.fromRGBO(31, 37, 51, 0.96),
        selectXAxisTextColor: const Color(0xFFFFFFFF),
        selectYAxisTextColor: const Color(0xFFFFFFFF),
      );

  ChartColors merge(ChartColors? other) {
    if (other == null) return this;
    return ChartColors(
      bgColor: other.bgColor ?? this.bgColor,
      kLineColor: other.kLineColor ?? this.kLineColor,
      gridColor: other.gridColor ?? this.gridColor,
      kLineShadowColor: other.kLineShadowColor ?? this.kLineShadowColor,
      ma5Color: other.ma5Color ?? this.ma5Color,
      ma9Color: other.ma9Color ?? this.ma9Color,
      ma20Color: other.ma20Color ?? this.ma20Color,
      upColor: other.upColor ?? this.upColor,
      dnColor: other.dnColor ?? this.dnColor,
      volColor: other.volColor ?? this.volColor,
      macdColor: other.macdColor ?? this.macdColor,
      difColor: other.difColor ?? this.difColor,
      deaColor: other.deaColor ?? this.deaColor,
      kColor: other.kColor ?? this.kColor,
      dColor: other.dColor ?? this.dColor,
      jColor: other.jColor ?? this.jColor,
      rsiColor: other.rsiColor ?? this.rsiColor,
      yAxisTextColor: other.yAxisTextColor ?? this.yAxisTextColor,
      xAxisTextColor: other.xAxisTextColor ?? this.xAxisTextColor,
      maxMinTextColor: other.maxMinTextColor ?? this.maxMinTextColor,
      depthBuyColor: other.depthBuyColor ?? this.depthBuyColor,
      depthSellColor: other.depthSellColor ?? this.depthSellColor,
      markerBorderColor: other.markerBorderColor ?? this.markerBorderColor,
      markerBgColor: other.markerBgColor ?? this.markerBgColor,
      markerInfoNameColor:
          other.markerInfoNameColor ?? this.markerInfoNameColor,
      markerInfoColor: other.markerInfoColor ?? this.markerInfoColor,
      realTimeBgColorFn: other.realTimeBgColorFn ?? this.realTimeBgColorFn,
      rightRealTimeBgColorFn:
          other.rightRealTimeBgColorFn ?? this.rightRealTimeBgColorFn,
      rightRealTimeTextColorFn:
          other.rightRealTimeTextColorFn ?? this.rightRealTimeTextColorFn,
      realTimeTextBorderColorFn:
          other.realTimeTextBorderColorFn ?? this.realTimeTextBorderColorFn,
      realTimeTextColorFn:
          other.realTimeTextColorFn ?? this.realTimeTextColorFn,
      realTimeLineColorFn:
          other.realTimeLineColorFn ?? this.realTimeLineColorFn,
      realTimeLongLineColorFn:
          other.realTimeLongLineColorFn ?? this.realTimeLongLineColorFn,
      simpleLineUpColor: other.simpleLineUpColor ?? this.simpleLineUpColor,
      simpleLineDnColor: other.simpleLineDnColor ?? this.simpleLineDnColor,
      vCrossColor: other.vCrossColor ?? this.vCrossColor,
      hCrossColor: other.hCrossColor ?? this.hCrossColor,
      selectXAxisTextBgColor:
          other.selectXAxisTextBgColor ?? this.selectXAxisTextBgColor,
      selectYAxisTextBgColor:
          other.selectYAxisTextBgColor ?? this.selectYAxisTextBgColor,
      selectXAxisTextColor:
          other.selectXAxisTextColor ?? this.selectXAxisTextColor,
      selectYAxisTextColor:
          other.selectYAxisTextColor ?? this.selectYAxisTextColor,
    );
  }
}

class ChartStyle {
  const ChartStyle({
    this.candleMargin = 2,
    this.candleWidth = 8,
    this.candleRadius = 0,
    this.candleLineWidth = 1,
    this.volWidth = 8.0,
    this.macdWidth = 3.0,
    this.vCrossWidth = 0.5,
    this.hCrossWidth = 0.5,
    this.gridRows = 4,
    this.gridColumns = 5,
    this.topPadding = 24,
    this.bottomDateHigh = 18,
    this.bottomDatePaddingTop = 4,
    this.childPadding = 25,
    this.defaultTextSize = 10,
    this.rightTextMarginRight = 2,
  });

  // ///点与点的距离
  // final double pointWidth;

  ///蜡烛宽度
  final double? candleWidth;

  final double? candleRadius;

  ///每根蜡烛数据之间的间隔
  final double? candleMargin;

  ///蜡烛中间线的宽度
  final double? candleLineWidth;

  ///vol柱子宽度
  final double? volWidth;

  ///macd柱子宽度
  final double? macdWidth;

  ///垂直交叉线宽度
  final double? vCrossWidth;

  ///水平交叉线宽度
  final double? hCrossWidth;

  ///网格
  final int? gridRows;
  final int? gridColumns;

  final double? topPadding;

  final double? bottomDateHigh;
  final double? bottomDatePaddingTop;

  final double? childPadding;

  final double? defaultTextSize;

  final double? rightTextMarginRight;

  ChartStyle copyWith({
    double? candleMargin,
    double? candleWidth,
    double? candleRadius,
    double? candleLineWidth,
    double? volWidth,
    double? macdWidth,
    double? vCrossWidth,
    double? hCrossWidth,
    int? gridRows,
    int? gridColumns,
    double? topPadding,
    double? bottomDateHigh,
    double? bottomDatePaddingTop,
    double? childPadding,
    double? defaultTextSize,
    double? rightTextMarginRight,
  }) {
    return ChartStyle(
      candleMargin: candleMargin ?? this.candleMargin,
      candleWidth: candleWidth ?? this.candleWidth,
      candleRadius: candleRadius ?? this.candleRadius,
      candleLineWidth: candleLineWidth ?? this.candleLineWidth,
      volWidth: volWidth ?? this.volWidth,
      macdWidth: macdWidth ?? this.macdWidth,
      vCrossWidth: vCrossWidth ?? this.vCrossWidth,
      hCrossWidth: hCrossWidth ?? this.hCrossWidth,
      gridRows: gridRows ?? this.gridRows,
      gridColumns: gridColumns ?? this.gridColumns,
      topPadding: topPadding ?? this.topPadding,
      bottomDateHigh: bottomDateHigh ?? this.bottomDateHigh,
      bottomDatePaddingTop: bottomDatePaddingTop ?? this.bottomDatePaddingTop,
      childPadding: childPadding ?? this.childPadding,
      defaultTextSize: defaultTextSize ?? this.defaultTextSize,
      rightTextMarginRight: rightTextMarginRight ?? this.rightTextMarginRight,
    );
  }

  ChartStyle merge(ChartStyle? other) {
    if (other == null) return this;
    return copyWith(
      candleMargin: other.candleMargin ?? this.candleMargin,
      candleWidth: other.candleWidth ?? this.candleWidth,
      candleRadius: other.candleRadius ?? this.candleRadius,
      candleLineWidth: other.candleLineWidth ?? this.candleLineWidth,
      volWidth: other.volWidth ?? this.volWidth,
      macdWidth: other.macdWidth ?? this.macdWidth,
      vCrossWidth: other.vCrossWidth ?? this.vCrossWidth,
      hCrossWidth: other.hCrossWidth ?? this.hCrossWidth,
      gridRows: other.gridRows ?? this.gridRows,
      gridColumns: other.gridColumns ?? this.gridColumns,
      topPadding: other.topPadding ?? this.topPadding,
      bottomDateHigh: other.bottomDateHigh ?? this.bottomDateHigh,
      bottomDatePaddingTop:
          other.bottomDatePaddingTop ?? this.bottomDatePaddingTop,
      childPadding: other.childPadding ?? this.childPadding,
      defaultTextSize: other.defaultTextSize ?? this.defaultTextSize,
      rightTextMarginRight:
          other.rightTextMarginRight ?? this.rightTextMarginRight,
    );
  }
}
